import Vue from 'vue'

import 'normalize.css/normalize.css'// A modern alternative to CSS resets

import Element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import '@/styles/index.scss' // global css
import formCreate from '@form-create/element-ui'
import UploadImage from '@/components/UploadImage'

// import '@/styles/element-variables.scss'

import App from './App'
import router from './router'
import store from './store'

import i18n from './lang' // Internationalization
import './icons' // icon
import './errorLog'// error log
import './permission' // permission control
import Print from 'vue-print-nb'
import * as filters from './filters' // global filters
import './utils/flexible'
import moment from 'moment';



moment.locale('zh-cn');

Vue.use(Element, {
  size: 'medium', // set element-ui default size
  i18n: (key, value) => i18n.t(key, value)
})
Vue.use(formCreate)
// register global utility filters.
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})
Vue.component('UploadImage', UploadImage)
Vue.config.productionTip = false
Vue.use(Print)

router.beforeEach((to, from, next) => {
  next()
})

new Vue({
  el: '#app',
  router,
  store,
  i18n,
  template: '<App/>',
  components: { App }
})

/**
 * 使用：v-permission="'resCode'"
 *   resCode 按钮资源（即路由path）
 * **/
Vue.directive('permission', {
  inserted(el, vDir) {
    const btnPermission = store.getters.buttons
    const { account } = store.getters.userInfo
    if (account === 'admin' || vDir.value == 'admin') return
    // console.log(btnPermission.includes('allot:save'),vDir.value)

    if (vDir.value && !btnPermission.includes(vDir.value)) {
      el.parentNode.removeChild(el)
    }
  }
})

//
// //全局钩子检查
// router.beforeEach((to,from,next) =>{
//   console.log("before");
//   //检查如果没有登录或者过期则跳转到登录
//   if(to.fullPath === '/login'){
//     next('/login')
//   }else{
//     next()
//   }
// });
